package weibo4android.androidexamples;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.RequestToken;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LoginActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
		System.setProperty("weibo4j.oauth.consumerSecret",Weibo.CONSUMER_SECRET);
		Button beginOuathBtn = (Button) findViewById(R.id.login_Button01);
		
		 if(getIntent().getBooleanExtra("isHave", false)==true){
			 Intent intent = new Intent(LoginActivity.this,MainActivity.class);
				intent.putExtra("isHave", true);
				startActivity(intent);
				finish();
		 }else{		 
		 
		beginOuathBtn.setOnClickListener(new Button.OnClickListener() {

			public void onClick(View v) {

					Weibo weibo = OAuthConstant.getInstance().getWeibo();
					RequestToken requestToken;
					try {
						requestToken = weibo.getOAuthRequestToken("weibo4android://OAuthActivity");
						OAuthConstant.getInstance().setRequestToken(requestToken);
						Uri uri = Uri.parse(requestToken.getAuthenticationURL()
								+ "&display=mobile");
						startActivity(new Intent(Intent.ACTION_VIEW, uri));
					} catch (WeiboException e) {
						e.printStackTrace();
					}
				
				finish();
			}
		});
		
		 }
	}
}
